package com.starmark.sys.org.provider.web;


import com.starmark.core.framework.base.AbstractController;
import com.starmark.sys.org.provider.constants.OrgApiConstant;
import com.starmark.sys.org.provider.service.IOrgAddressService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Map;


/**
 * 组通讯录地址本API接口
 */
@RestController
@Api(value = "通讯录地址本", description = "通讯录地址本")
@RequestMapping(value = "/sys/org/address")
public class SysOrgAddressController extends AbstractController {

    @Autowired
    private IOrgAddressService orgAddressService;


    @ApiOperation(value = "查询部门下的组织信息")
    @PostMapping(value = "/tree")
    public Object tree(@RequestBody Map<String, Object> param) {
        int orgType = param.get("orgType") == null ? OrgApiConstant.ORG_ALL : (int) param.get("orgType");
        String id = param.get("id") == null ? "" : param.get("id") + "";
        return orgAddressService.getOrgTreeById(orgType, id);
    }


    @ApiOperation(value = "查询组织架构信息")
    @PostMapping(value = "/search")
    public Object search(@RequestBody Map<String, Object> param) {
        int orgType = param.get("orgType") == null ? OrgApiConstant.ORG_PERSON : (int) param.get("orgType");
        String searchKey = param.get("searchKey") == null ? "" : param.get("searchKey") + "";
        int pageSize = param.get("pageSize") == null ? 15 : Integer.parseInt(param.get("pageSize") + "");

        return orgAddressService.getOrgTreeBySearchkey(orgType, searchKey, pageSize);
    }


}
